var nodemailer = require('nodemailer');
var axios = require('axios');
var sendUser = 'lingshibococo@163.com';
var sendUserName = 'sweetQwQ';
var receiveUser = '3131912289@qq.com';
var transporter = nodemailer.createTransport({
    service: "163",
    secure: true,
    auth: {
        user: sendUser,
        pass: "ALXSVDIDDYCDCUDB" //  授权码
    }
});
function getDate() {
    var now = new Date();
    function getDay() {
        switch (now.getDay()) {
            case 0:
                return '星期天';
            case 1:
                return '星期一';
            case 2:
                return '星期二';
            case 3:
                return '星期三';
            case 4:
                return '星期四';
            case 5:
                return '星期五';
            case 6:
                return '星期六';
        }
    }
    return "\u4ECA\u5929\u662F\uFF1A".concat(now.getFullYear(), "\u5E74").concat(now.getMonth() + 1, "\u6708").concat(now.getDate(), "\u65E5 ").concat(getDay());
}
function getProbability(val) {
    return Math.floor(Math.random() * 100) <= val;
}
function sendEmail() {
    axios.get('http://wthrcdn.etouch.cn/weather_mini?citykey=101020100')
        .then(function (response) {
        var weather = {
            message: response.data.data.ganmao,
            city: response.data.data.city,
            high: '最' + response.data.data.forecast[0].high,
            low: '最' + response.data.data.forecast[0].low,
            wind: response.data.data.forecast[0].fengxiang + response.data.data.forecast[0].fengli.substring(9, 11)
        };
        var message = [['今天你学习了吗？', '今天你当懒狗了吗？', '还打算考研吗？', '跟老公说早上好了吗？'], ['不会还没起床吧？', '不会还在床上睡觉吧？', '不会还躺床上玩手机吧？', '不会还在躺尸吧？']];
        var mailOptions = {
            from: "".concat(sendUserName, "<").concat(sendUser, ">"),
            to: receiveUser,
            subject: "起床小助手",
            html: "<H2>".concat(getDate(), "</H2><h3>").concat(weather.city, "\u5929\u6C14\uFF1A").concat(weather.high, ",").concat(weather.low, ",").concat(weather.wind, "</h3><h4>").concat(weather.message, "</h4><p>").concat(message[0][Math.floor(Math.random() * message[0].length)]).concat(message[1][Math.floor(Math.random() * message[1].length)], "</p>")
        };
        transporter.sendMail(mailOptions, function (err, data) {
            if (err) {
                console.log(err);
            }
            else {
                console.log(data);
            }
        });
        console.log('邮件发送成功！');
    })["catch"](function (error) {
        console.log(error);
    });
}
setInterval(function () {
    var now = new Date();
    console.log(getProbability(10));
    console.log("".concat(now.getFullYear(), "\u5E74").concat(now.getMonth() + 1, "\u6708").concat(now.getDate(), "\u65E5 ").concat(now.getHours(), ":").concat(now.getMinutes(), ":").concat(now.getSeconds()));
    if (new Date().getHours() === 7 && new Date().getMinutes() === 0) {
        sendEmail();
    }
}, 60000);
